
*****************
* R's Siblings *
*****************

*sibling info not available.

*********************
* R's Own fertility *
*********************

* # (living) boys
	gen R_num_boys_living =.
	replace R_num_boys_living = (v139/10) +1 if v139<80
	replace R_num_boys_living = 0 if v139==80 | v139==91 
	tab R_num_boys_living, m //note: "6" is actually 6+. Coded as 6 to be conservative.
	label var R_num_boys_living "# of R's living male children"

*Flag indeterminate (high) # of boys
	gen flag_6plusboys = (R_num_boys_living==6) if R_num_boys_living<.
	tab flag_6plusboys, m
	label var flag_6plusboys "Flag =1 if R has an indeterminate (6+) # of boys"
	
* # (living) girls
	gen R_num_girls_living = (v140/10) +1 if v140<80 
	replace R_num_girls_living = 0 if v140==80 | v140==91 
	tab R_num_girls_living, m //note: "6" is actually 6+. Coded as 6 to be conservative.
	label var R_num_girls_living "# of R's living female children"

*Flag indeterminate (high) # of girls
	gen flag_6plusgirls = (R_num_girls_living==6) if R_num_girls_living<.
	tab flag_6plusgirls, m
	label var flag_6plusgirls "Flag =1 if R has an indeterminate (6+) # of girls"

* # of living kids
	gen R_numkids_living =.
	replace R_numkids_living = R_num_girls_living + R_num_boys_living if (R_num_girls_living!=. & R_num_boys_living!=.)
	replace R_numkids_living = R_num_girls_living if (R_num_girls_living!=. & R_num_boys_living==.)
	replace R_numkids_living = R_num_boys_living if (R_num_girls_living==. & R_num_boys_living!=.)
	tab R_numkids_living, m
	label var R_numkids_living "# of R's kids who are living"

* # of deceased kids
	gen R_numkids_dead = v145 if v145!=.
	tab R_numkids_dead, m
	label var R_numkids_dead "# of R's kids who are deceased"
	
* Flag indeterminate high # of deceased kids
	gen flag_6plus_deadkids = (R_numkids_dead==6) if R_numkids_dead<.
	tab flag_6plus_deadkids,m 
	label var flag_6plus_deadkids "Flag =1 if R has an indeterminate (6+) # of dead kids"
	
* # of kids ever (i.e., living + deceased)
	gen R_numkids_ever =. 
	replace R_numkids_ever = R_numkids_living + R_numkids_dead if (R_numkids_living!=. & R_numkids_dead!=.)
	replace R_numkids_ever = R_numkids_living if (R_numkids_living!=. & R_numkids_dead==.)
	replace R_numkids_ever = R_numkids_dead if (R_numkids_living==. & R_numkids_dead!=.)
	tab R_numkids_ever, m
	label var R_numkids_ever "# of kids that R has ever had (living or deceased)"

* Dummy: has R ever had kids
	gen R_kids_ever = (R_numkids_ever!=0) if R_numkids_ever<.
	tab R_kids_ever,m 
	label var R_kids_ever "Dummy=1 if R has ever had kids"

*Dummy: does R have kids right now (i.e. if no, then R either has never had kids or num kids living is 0)
	gen R_kids_now = (R_numkids_living!=0) if R_numkids_living<. 
	tab R_kids_now,m 

*********************************
* # of persons in R's household *
*********************************

* # of kids (of any age) living in R's hh
	gen R_totnumkids_livinginhh = R_numkids_living if (v143<70) & (R_numkids_living!=. & v143!=.) 
	replace R_totnumkids_livinginhh = 0 if (v143==70 | v143==80) & (R_numkids_living!=. & v143!=.)
	replace R_totnumkids_livinginhh = R_numkids_living if v143==91 
	tab R_totnumkids_livinginhh, m 
	label var R_totnumkids_livinginhh "Total # of kids (of any age) living in R's hh (R0050100)"	

* # of children 0-17 living in R's hh
//NOTE: in avtmh57, I can only see if a child is <=16 or if the child is 17+. 

	gen R_totnumkids_0to17_livinginhh = R_numkids_living if (inlist(v143,0,10,30)) & (R_numkids_living!=. & v143!=.)
	replace R_totnumkids_0to17_livinginhh =0 if (inlist(v143,20,70,80)) & (R_numkids_living!=. & v143!=.)
	replace R_totnumkids_0to17_livinginhh = R_numkids_living if v143==91 
	tab R_totnumkids_0to17_livinginhh,m 
	label var R_totnumkids_0to17_livinginhh "Total # of kids (0-17) living in R's hh"
	 
* total # of people living in R's household

//intermediate step: flag indeterminate (high) # of adults in an hh
	gen flag_10plus_adultsinhh = (v10==8) if v10!=.
	tab flag_10plus_adultsinhh,m 
	label var flag_10plus_adultsinhh "Dummy =1 if R's hh has an indeterminate # of adults (10+)"
	
	gen R_hhsize_plusR = R_totnumkids_0to17_livinginhh + v10 if (R_totnumkids_0to17_livinginhh!=. & v10!=.) 	
	tab R_hhsize_plusR,m //Note: only Rs with info on both # of kids 0-17 in hh and # of adults in the hh are given values for hh size. 
	
	gen R_hhsize_minusR = R_hhsize_plusR -1
	tab R_hhsize_minusR,m 
	
	label var R_hhsize_plusR "total # of persons in R's hh (including R)"
	label var R_hhsize_minusR "total # of persons in R's hh (NOT including R)"		
	
